
export function pageMixin(queryPromise, extraParams = {}) {
	
	
	return {
  data() {
    return {
      dataList: [],  // 存储数据列表
      pagination: {},  // 存储分页信息
    };
  },
  methods: {
    // 分页查询
    async queryListByPage(params = {}) {
      const response = await queryPromise({
        page: 1,
        pageSize: 20,
        ...params,
        ...extraParams,
      });
      if (params.page && params.page > 1) {
        this.dataList = [...this.dataList, ...response.result];
        this.pagination = response.pagination;
      } else {
        this.dataList = response.result;
        this.pagination = response.pagination;
      }
    },
    
    // 向下加载更多
    toLowerAction() {
      if (this.pagination.page < this.pagination.totalPage) {
        this.queryListByPage({
          page: this.pagination.page + 1,
        });
      }
    },

    // 刷新
    refreshAction() {
      this.queryListByPage();
    }
  },
  mounted() {
    this.queryListByPage(); // 在组件挂载后调用查询函数
  },
}
};
